package controller.ur;

import java.io.IOException;
import java.util.List;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.dao.AlbumDaoLocal;
import model.dao.PhotoDaoLocal;
import model.entity.Album;
import model.entity.Photo;
import model.entity.User;
import controller.CUtil;

/**
 * Servlet implementation class SChangePhotoSettings
 */
public class SChangePhotoSettings extends HttpServlet {
	private static final long serialVersionUID = 1L;
      
	@EJB
	private PhotoDaoLocal photoDao;
	/*
	@EJB
	private AlbumDaoLocal albumDao;
	*/
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SChangePhotoSettings() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if(!CUtil.checkLogIn(request, response))
			return;
		Integer photoId=Integer.parseInt((String)request.getParameter("photoId"));
		Photo photo=photoDao.findById(photoId);
		request.setAttribute("photo", photo);
		//List<Album> albums=albumDao.findAlbumByUser(user.getId());
		//request.setAttribute("albums", albums);
		Album currentAlbum=null;
		for(Album album:photo.getAlbums()){
			if(!album.getFavorite()){
				currentAlbum=album;
				break;
			}
		}
		request.setAttribute("currentAlbum", currentAlbum);
		CUtil.redirecter(request, response, "ur/VChangePhotoSettings.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request,response);
	}

}
